package com.wang.test.demo.putong;

import lombok.Data;

import java.util.concurrent.atomic.AtomicInteger;

@Data
public class Phone {

    //手机余额
    private AtomicInteger count = new AtomicInteger(3);

    private Phone(){}

    //private static Phone phone;

//    public static Phone getInstance(){
//        if (phone == null){
//            synchronized(Phone.class) { // 此处为类级别的锁
//               if (phone == null) {
//                   phone = new Phone();
//               }
//            }
//        }
//        return phone;
//    }
    private static class SingletonHolder{
        private static final Phone phone = new Phone();
    }
    public static Phone getInstance() {
        return SingletonHolder.phone;
    }

    public int getReduce(){
        return count.decrementAndGet();
    }

}

